home *** CD-ROM | disk | FTP | other *** search
/ Clickx 96 / Clickx 96.iso / software / tools / tool / xbmc-10.1.exe / addons / script.module.pil / lib / PIL / MicImagePlugin.py < prev    next >
Encoding:
Python Source  |  2009-04-06  |  2.1 KB  |  96 lines

  1. #
  2. # The Python Imaging Library.
  3. # $Id$
  4. #
  5. # Microsoft Image Composer support for PIL
  6. #
  7. # Notes:
  8. #       uses TiffImagePlugin.py to read the actual image streams
  9. #
  10. # History:
  11. #       97-01-20 fl     Created
  12. #
  13. # Copyright (c) Secret Labs AB 1997.
  14. # Copyright (c) Fredrik Lundh 1997.
  15. #
  16. # See the README file for information on usage and redistribution.
  17. #
  18.  
  19.  
  20. __version__ = "0.1"
  21.  
  22.  
  23. import Image, TiffImagePlugin
  24. from OleFileIO import *
  25.  
  26.  
  27. #
  28. # --------------------------------------------------------------------
  29.  
  30.  
  31. def _accept(prefix):
  32.     return prefix[:8] == MAGIC
  33.  
  34. ##
  35. # Image plugin for Microsoft's Image Composer file format.
  36.  
  37. class MicImageFile(TiffImagePlugin.TiffImageFile):
  38.  
  39.     format = "MIC"
  40.     format_description = "Microsoft Image Composer"
  41.  
  42.     def _open(self):
  43.  
  44.         # read the OLE directory and see if this is a likely
  45.         # to be a Microsoft Image Composer file
  46.  
  47.         try:
  48.             self.ole = OleFileIO(self.fp)
  49.         except IOError:
  50.             raise SyntaxError, "not an MIC file; invalid OLE file"
  51.  
  52.         # find ACI subfiles with Image members (maybe not the
  53.         # best way to identify MIC files, but what the... ;-)
  54.  
  55.         self.images = []
  56.         for file in self.ole.listdir():
  57.             if file[1:] and file[0][-4:] == ".ACI" and file[1] == "Image":
  58.                 self.images.append(file)
  59.  
  60.         # if we didn't find any images, this is probably not
  61.         # an MIC file.
  62.         if not self.images:
  63.             raise SyntaxError, "not an MIC file; no image entries"
  64.  
  65.         self.__fp = self.fp
  66.         self.frame = 0
  67.  
  68.         if len(self.images) > 1:
  69.             self.category = Image.CONTAINER
  70.  
  71.         self.seek(0)
  72.  
  73.     def seek(self, frame):
  74.  
  75.         try:
  76.             filename = self.images[frame]
  77.         except IndexError:
  78.             raise EOFError, "no such frame"
  79.  
  80.         self.fp = self.ole.openstream(filename)
  81.  
  82.         TiffImagePlugin.TiffImageFile._open(self)
  83.  
  84.         self.frame = frame
  85.  
  86.     def tell(self):
  87.  
  88.         return self.frame
  89.  
  90. #
  91. # --------------------------------------------------------------------
  92.  
  93. Image.register_open("MIC", MicImageFile, _accept)
  94.  
  95. Image.register_extension("MIC", ".mic")
  96.